package com.wechat.bot.config;


import com.wechat.bot.common.file.FileUtil;
import com.wechat.bot.common.ini.IniReader;
import com.wechat.bot.common.log.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;


public class ConfigManagement {

    public static Map<String, Properties> readIniConf(String iniConfPath) {
        // 如果是相对路径
        if (!FileUtil.isAbsolutePath(iniConfPath)) {
            iniConfPath = System.getProperty("user.dir") + File.separator + iniConfPath;
        }

        Map<String, Properties> iniConf = new HashMap<String, Properties>();
        IniReader ir = null;
        InputStream is = null;
        try {
            is = new FileInputStream(iniConfPath);
            ir = new IniReader(is);
        } catch (IOException e) {
            Log.error("加载配置文件失败: " + iniConfPath, e);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        iniConf = ir.get();

        return iniConf;
    }
}
